package com.orm.mapper;

import java.io.Serializable;
import java.util.List;

/**
 * 服务层基础接口
 */
public interface IService<T> {
	
	// 返回 baseMapper
	BaseMapper<T> getBaseMapper();
	
	// 返回 实体类 T
	Class<T> getEntityClass();
	
	
	default T getById(Serializable id) {
		return this.getBaseMapper().selectById(id);
	}
	
	
	// 需要找下主键，看主键是否为null
	abstract boolean saveOrUpdate(T entity);
	
	
	default boolean save(T entity) {
		return this.getBaseMapper().insert(entity) >= 0;
	}
	
	default boolean update(T entity){
		return this.getBaseMapper().updateById(entity) >= 1;
	}
	
	
	default List<T> listAll(){
		return this.getBaseMapper().selectAll();
	}
	
	default boolean removeById(Serializable entity) {
		return this.getBaseMapper().deleteById(entity) >= 1;
	}
}
